{% extends 'base.html' %}
{% load render_table from django_tables2 %}
{% load staticfiles %}

{% block header %}
    <a href="javascript:;" class="active">组管理</a>
{% endblock %}

{% block action %}
    <a class="roll-nav roll-right extra-right-btns pull-right" href="{% url 'permissions:group_create' %}">
        <i class="fa fa-plus"></i>
        添加新分组
    </a>
{% endblock %}

{% block main %}
<div class="wrapper wrapper-content">
    <div class="extra-box-content">
        {% render_table table "table.html" %}
    </div>
</div>
{% endblock %}


{% block js %}
    {{ block.super }}
<script type="text/javascript">
    $(".perms-group-delete").on("click", function() {
        var $this = $(this);
        var entity_id = $this.data("entity_id");
        swal({
            title: "您确定要删除吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            confirmButtonColor: "#ff6700",
            confirmButtonText: "删除",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: true
        }, function(isConfirm) {
            if (isConfirm) {
                $.ajax({
                    method: "DELETE",
                    url: "{{ request.get_full_path }}",
                    data: {entity_id: entity_id},
                    dataType: "json",
                    success: function(data) {
                        if (data.state) {
                            swal({
                                title: "删除成功!",
                                type: "success",
                                timer: 800,
                                showCancelButton: false,
                                showConfirmButton: false
                            });
                            $this.parent().parent().css("display", "none");
                        } else {
                            swal({
                                title: "删除失败!",
                                type: "danger",
                            });
                        }
                    }
                });
             }
         });
    });
</script>
{% endblock %}
